import { queryResolution } from '../data/resolution';
import { librarySizeList, queryLibrarySize } from '../data/library.size';
import type { LabeledValue } from 'ant-design-vue/es/select';
import { listStore } from '../auth/store';
import { fetchOptions } from '@/utils/common/bin';
import { queryCategory } from '../data/classify';
import { queryStation } from '../esl/station';
import { QUERY_SCOPE } from '@/enum/system';

const eslResolutionOptions = ref<LabeledValue[]>([]);
const lcdResolutionOptions = ref<LabeledValue[]>([]);

const storeOptions = ref<LabeledValue[]>([]);
const productClassifyOptions = ref<LabeledValue[]>([]);
const listLibrarySizeOptions = ref<LabeledValue[]>([]);
const stationOptions = ref<LabeledValue[]>([]);

export const getLibrarySizeOptions = async () => {
  const { data } = await librarySizeList({
    pageNum: 1,
    pageSize: 40,
    total: 0,
  });

  return fetchOptions(listLibrarySizeOptions, {
    labelKey: 'sizeDesc',
    valueKey: 'sizeId',
    rows: data.rows,
  });
};

export const getEslResolutionOptions = async () => {
  const { data } = await queryResolution();
  return fetchOptions(eslResolutionOptions, {
    labelKey: 'description',
    valueKey: 'resolutionId',
    rows: data.data,
  });
};

export const getProductClassifyOptions = async () => {
  const { data } = await queryCategory();
  return fetchOptions(productClassifyOptions, {
    labelKey: 'categoryName',
    valueKey: 'categoryId',
    rows: data.data,
  });
};
export const getLcdResolutionOptions = async () => {
  const { data } = await queryLibrarySize();
  return fetchOptions(lcdResolutionOptions, {
    labelKey: 'sizeDesc',
    valueKey: 'sizeId',
    rows: data.data,
  });
};

export const getStoreOptions = async () => {
  const { data } = await listStore({ pageNum: 1, pageSize: 100, scope: QUERY_SCOPE.ALL });
  return fetchOptions(storeOptions, {
    labelKey: 'storeName',
    valueKey: 'id',
    rows: data.rows,
  });
};

export const getStationOptions = async () => {
  const { data } = await queryStation();
  return fetchOptions(stationOptions, {
    labelKey: 'stationName',
    valueKey: 'stationId',
    rows: data.data,
  });
};

export {
  eslResolutionOptions,
  lcdResolutionOptions,
  storeOptions,
  stationOptions,
  productClassifyOptions,
  listLibrarySizeOptions,
};
